<template>
  <div>
    <h1>User Information</h1>
    <div v-if="users.length > 0">
      <div v-for="user in users" :key="user.id">
        <p><strong>ID:</strong> {{ user.id }}</p>
        <p><strong>Name:</strong> {{ user.name }}</p>
      </div>
    </div>
    <div v-else>
      <p>Loading user information...</p>
    </div>
  </div>
</template>

<script>
import axios from 'axios';

export default {
  data() {
    return {
      users: [], // 用于存储从后端获取的用户信息
    };
  },
  created() {
    this.getUserData(); // 组件创建时调用获取数据的方法
  },
  methods: {
    async getUserData() {
      try {
        const response = await axios.get('http://localhost:8888/users/get-allusers'); // 向后端请求数据
        this.users=response.data;
      } catch (error) {
        console.error('Error fetching user data:', error);
      }
    },
  },
};
</script>

<style scoped>
/* 你可以在这里添加一些样式 */
div {
  font-family: Arial, sans-serif;
  padding: 20px;
}

h1 {
  color: #4CAF50;
}

p {
  font-size: 18px;
}
</style>
